package com.jatosoft.poc.jsf.managedbean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jatosoft.accounting.webapp.UIModel;
import com.jatosoft.poc.priceinquiry.core.domain.BaseDomain;

public class BaseManagedBean implements Serializable {

	private static final long serialVersionUID = -3659574556647853643L;
	protected Log logger = LogFactory.getLog(this.getClass());
	
	String userId;
	List<UIModel> uiModels = new ArrayList<UIModel>();
	UIModel uiModel = new UIModel();

	void dumpModel2UIModel(List<? extends BaseDomain> models) {
		uiModels.clear();

		for (BaseDomain m : models) {
			UIModel um = new UIModel(m);
			uiModels.add(um);
		}
	}
	
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public FacesContext getFacesContext() {
		return FacesContext.getCurrentInstance();
	}

	public void addMessage(String msg) {
		getFacesContext().addMessage(null, new FacesMessage(msg));
	}

	public List<UIModel> getUiModels() {
		return uiModels;
	}

	public void setUiModels(List<UIModel> uiModels) {
		this.uiModels = uiModels;
	}

	public UIModel getUiModel() {
		return uiModel;
	}

	public void setUiModel(UIModel uiModel) {
		this.uiModel = uiModel;
	}


}
